$(function () {

    $("#jqGrid").jqGrid({
        url: baseURL + 'api/bothercost/list?aguid='+GetUrlParam("aguid"),
        datatype: "json",
        colModel: [
            {label: 'guid', name: 'guid', index: 'guid', width: 50, key: true , hidden: true},
            {label: '所属申请书ID', name: 'aGuid', index: 'a_guid', width: 80, hidden: true},
            {label: '序号', name: 'oCNum', index: 'o_c_num', width: 80},
            {label: '其他费用明细', name: 'oCDetail', index: 'o_c_detail', width: 80},
            {label: '计取依据及说明', name: 'oCExplain', index: 'o_c_explain', width: 80},
            {label: '排序号', name: 'oCSort', index: 'o_c_sort', width: 80},
            {label: '是否汇总项', name: 'oCToll', index: 'o_c_toll', width: 80}
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        q:{
            oCDetail: null
        },
        showList: true,
        title: null,
        bOtherCost: {},
        aGuid: GetUrlParam("aguid"),
        status: ["是", "否"]

    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.bOtherCost = {aGuid:GetUrlParam("aguid")};


        },
        query: function () {
            vm.reload();
        },
        update: function (event) {
            var guid = getSelectedRow();
            if (guid == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";
            vm.aGuid = GetUrlParam("aguid");
            vm.getInfo(guid)
        },
        saveOrUpdate: function (event) {
            var url = vm.bOtherCost.guid == null ? "api/bothercost/save" : "api/bothercost/update";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(vm.bOtherCost),
                success: function (r) {
                    if (r.code === 0) {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        del: function (event) {
            var guids = getSelectedRows();
            if (guids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                $.ajax({
                    type: "POST",
                    url: baseURL + "api/bothercost/delete",
                    contentType: "application/json",
                    data: JSON.stringify(guids),
                    success: function (r) {
                        if (r.code == 0) {
                            alert('操作成功', function (index) {
                                $("#jqGrid").trigger("reloadGrid");
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        getInfo: function (guid) {
            $.get(baseURL + "api/bothercost/info/" + guid, function (r) {
                vm.bOtherCost = r.bOtherCost;
                vm.bOtherCost.aGuid = GetUrlParam("aguid");
            });
        }
        ,
        reload: function (event) {
            vm.showList = true;

            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData:{'oCDetail': vm.q.oCDetail},
                page: page
            }).trigger("reloadGrid");
        }
    }
});